this.BX=this.BX||{};this.BX.Seo=this.BX.Seo||{};(function(e,t,n){"use strict";var s,a,l,o,i;function r(e,t){var n=typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=c(e))||t&&e&&typeof e.length==="number"){if(n)e=n;var s=0;var a=function e(){};return{s:a,n:function t(){if(s>=e.length)return{done:true};return{done:false,value:e[s++]}},e:function e(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=true,o=false,i;return{s:function t(){n=n.call(e)},n:function e(){var t=n.next();l=t.done;return t},e:function e(t){o=true;i=t},f:function e(){try{if(!l&&n["return"]!=null)n["return"]()}finally{if(o)throw i}}}}function c(e,t){if(!e)return;if(typeof e==="string")return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor)n=e.constructor.name;if(n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}function u(e,t){if(t==null||t>e.length)t=e.length;for(var n=0,s=new Array(t);n<t;n++){s[n]=e[n]}return s}var d=function(){function e(s,a){babelHelpers.classCallCheck(this,e);this.container=s;this.canAddItems=!!a.canAddItems;this.canUnSelectItem=!!a.canUnSelectItem;this.onNewItemCallback=a.events&&t.Type.isFunction(a.events.onNewItem)?a.events.onNewItem:null;this.onSelectItemCallback=a.events&&t.Type.isFunction(a.events.onSelectItem)?a.events.onSelectItem:null;this.onUnSelectItemCallback=a.events&&t.Type.isFunction(a.events.onUnSelectItem)?a.events.onUnSelectItem:null;this.onRemoveItemCallback=a.events&&t.Type.isFunction(a.events.onRemoveItem)?a.events.onRemoveItem:null;this.init();this.setSelected(a.selected);this.setItems(a.items?a.items:{});this.enabled=true;this.loader=new n.Loader({size:20})}babelHelpers.createClass(e,[{key:"setSelected",value:function e(t){this.selected=t;this.closeMenu();this.updateClientHtml()}},{key:"setItems",value:function e(t){this.closeMenu();this.items=t}},{key:"init",value:function e(){t.Dom.append(this.getHtml(),this.container);this.updateClientHtml();t.Event.bind(this.container,"click",this.onContainerClick.bind(this))}},{key:"enable",value:function e(){this.enabled=true;var t=this.getSelectorNode();t?t.classList.remove("seo-ads-client-selector-loading"):false;this.loader.hide()}},{key:"disable",value:function e(){this.enabled=false;var t=this.getSelectorNode();t?t.classList.add("seo-ads-client-selector-loading"):false;this.loader.hide();if(t){t.classList.add("seo-ads-client-selector-loading");var n=t.getElementsByClassName("seo-ads-client-selector-loader")[0];this.loader.show(n)}}},{key:"getHtml",value:function e(){return t.Tag.render(s||(s=babelHelpers.taggedTemplateLiteral(['\n\t\t<div class="seo-ads-client">\n\t\t\t<div class="seo-ads-client-selector">\n\t\t\t\t<div class="seo-ads-client-selector-avatar" data-role="user-avatar"></div>\n\t\t\t\t<div class="seo-ads-client-selector-user">\n\t\t\t\t\t<a target="_top" data-role="user-name user-link" class="seo-ads-client-selector-user-link" title=""></a>\n\t\t\t\t</div>\n\t\t\t\t<span class="seo-ads-client-selector-arrow"></span>\n\t\t\t\t<span class="seo-ads-client-selector-loader"></span>\n\t\t\t</div>\n\t\t\t<div class="seo-ads-client-note">\n\t\t\t',"\n\t\t\t</div>\n\t\t</div>\n\t\t"])),t.Loc.getMessage("SEO_ADS_CLIENT_NOTE"))}},{key:"getMenuItemHtml",value:function e(n){var s=BX.util.htmlspecialchars(n.NAME);var i=t.Tag.render(a||(a=babelHelpers.taggedTemplateLiteral(["<div>\n\t\t\t",'\n\t\t\t<span class="seo-ads-client-menu-popup-user">','</span>\n\t\t\t<span class="seo-ads-client-menu-popup-shutoff" data-role="client-remove" data-client-id="','">',"</span>\n\t\t</div>"])),n.PICTURE?t.Tag.render(l||(l=babelHelpers.taggedTemplateLiteral(['<div class="seo-ads-client-menu-avatar" style="background-image: url(\'',"');\"></div>"])),n.PICTURE):t.Tag.render(o||(o=babelHelpers.taggedTemplateLiteral(['<div class="seo-ads-client-menu-avatar"></div>']))),s,n.CLIENT_ID,t.Loc.getMessage("SEO_ADS_CLIENT_DISCONNECT"));return i.innerHTML}},{key:"getRemoveConfirmPopupHtml",value:function e(n){var s=BX.util.htmlspecialchars(n.NAME);return t.Tag.render(i||(i=babelHelpers.taggedTemplateLiteral(['<div class="seo-ads-client-popup">\n\t\t\t<div class="seo-ads-client-popup-text">\n\t\t\t',"\n\t\t\t</div>\n\t\t</div>"])),t.Loc.getMessage("SEO_ADS_CLIENT_REMOVE").replace("#NAME#",s))}},{key:"updateClientHtml",value:function e(){var n="";var s="";var a="";var l=false;if(this.selected){n=this.selected.hasOwnProperty("PICTURE")?this.selected.PICTURE:"";s=this.selected.hasOwnProperty("NAME")?this.selected.NAME:t.Loc.getMessage("SEO_ADS_CLIENT_SELECTOR_UNTITLED");a=this.selected.hasOwnProperty("LINK")?this.selected.LINK:""}else{s=t.Loc.getMessage("SEO_ADS_CLIENT_SELECTOR_EMPTY");l=true}var o=this.getSelectorNode();if(l){o?o.classList.add("seo-ads-client-selector-empty"):false}else{o?o.classList.remove("seo-ads-client-selector-empty"):false}var i=this.container.querySelector('[data-role="user-avatar"]');var r=this.container.querySelector('[data-role*="user-name"]');var c=this.container.querySelector('[data-role*="user-link"]');if(n)i.style.backgroundImage="url('"+n+"')";else i.style.removeProperty("background-image");r.textContent=s;if(a)c.setAttribute("href",a);else c.removeAttribute("href")}},{key:"onSelectItem",value:function e(n){this.setSelected(n);if(t.Type.isFunction(this.onSelectItemCallback))this.onSelectItemCallback(n)}},{key:"onUnSelectItem",value:function e(){this.setSelected(null);if(t.Type.isFunction(this.onUnSelectItemCallback)){this.onUnSelectItemCallback()}}},{key:"onRemoveItem",value:function e(n){if(t.Type.isFunction(this.onRemoveItemCallback))this.onRemoveItemCallback(n)}},{key:"onContainerClick",value:function e(){var n=this;if(!this.enabled){return}var s=[];var a=r(this.items),l;try{for(a.s();!(l=a.n()).done;){var o=l.value;s.push({html:this.getMenuItemHtml(o),className:"seo-ads-client-menu menu-popup-no-icon",onclick:this.onSelectItem.bind(this,o)})}}catch(e){a.e(e)}finally{a.f()}if(this.canUnSelectItem){s.push({delimiter:true},{text:t.Loc.getMessage("SEO_ADS_CLIENT_NO_ACCOUNT"),onclick:this.onUnSelectItem.bind(this)})}if(this.canAddItems){s.push({delimiter:true},{text:t.Loc.getMessage("SEO_ADS_CLIENT_ADD"),onclick:function e(){n.closeMenu();if(t.Type.isFunction(n.onNewItemCallback))n.onNewItemCallback()}})}var i=this.getSelectorNode();BX.PopupMenu.show("clientsMenuDropdown",this.container,s,{offsetTop:0,offsetLeft:42,angle:true,events:{onPopupClose:function e(){i?i.classList.remove("seo-ads-client-selector-active"):false;BX.PopupMenu.destroy("clientsMenuDropdown")}}});i?i.classList.add("seo-ads-client-selector-active"):false;var c=BX.PopupMenu.currentItem.popupWindow.getContentContainer().querySelectorAll('[data-role="client-remove"]');var u=r(c),d;try{for(u.s();!(d=u.n()).done;){var v=d.value;t.Event.bind(v,"click",(function(e){e.stopPropagation();var t=BX.data(e.target,"client-id");n.closeMenu();var s=r(n.items),a;try{for(s.s();!(a=s.n()).done;){var l=a.value;if(l.CLIENT_ID==t){n.confirmRemoveItem(l)}}}catch(e){s.e(e)}finally{s.f()}}))}}catch(e){u.e(e)}finally{u.f()}}},{key:"confirmRemoveItem",value:function e(n){var s=this;var a=new BX.PopupWindow({content:this.getRemoveConfirmPopupHtml(n),autoHide:true,cacheable:false,closeIcon:true,closeByEsc:true,buttons:[new BX.UI.Button({text:t.Loc.getMessage("SEO_ADS_CLIENT_DISCONNECT"),color:BX.UI.Button.Color.DANGER,onclick:function e(t){a.close();s.onRemoveItem(n)}}),new BX.UI.Button({text:t.Loc.getMessage("SEO_ADS_CLIENT_BTN_CANCEL"),color:BX.UI.Button.Color.LINK,onclick:function e(){a.close()}})]});a.show()}},{key:"closeMenu",value:function e(){if(BX.PopupMenu.currentItem){BX.PopupMenu.currentItem.close()}}},{key:"destroy",value:function e(){if(BX.PopupMenu.currentItem){BX.PopupMenu.currentItem.close()}this.container.innerHTML=""}},{key:"getSelectorNode",value:function e(){var t=this.container.getElementsByClassName("seo-ads-client-selector");if(t)t=t[0];return t}}]);return e}();e.ClientSelector=d})(this.BX.Seo.Ads=this.BX.Seo.Ads||{},BX,BX);
//# sourceMappingURL=client_selector.bundle.map.js